#include"BlockQueue.hpp"
#include<functional>
using func_t =std::function<void()>;
BlockQueue<func_t> block_queue(3);
void* product(void* arg)
{
    std::string name=(char*)arg;
    for(int i=0;i<10;++i)
    {
        func_t func=[name,i](){std::cout<<"消费者执行"<<name<<"派发的任务:"<<i<<std::endl;};
        block_queue.Enqueue(func);
    }
    return nullptr;
}

void* execute(void* arg)
{
    for(int i=0;i<30;++i)
    {
        func_t func;
        block_queue.Pop(&func);
        func();
    }
    return nullptr;
}
int main()
{
    pthread_t t1,t2,t3,t4;
    pthread_create(&t1,nullptr,product,(void*)"thread_1");
    pthread_create(&t2,nullptr,product,(void*)"thread_2");
    pthread_create(&t3,nullptr,product,(void*)"thread_3");
    pthread_create(&t4,nullptr,execute,(void*)"thread_4");
    pthread_join(t1,nullptr);
    pthread_join(t2,nullptr);
    pthread_join(t3,nullptr);
    pthread_join(t4,nullptr);
    
    return 0;
}